"ui";
// let gz2 = '22';
ui.layout(
    <vertical margin="30">
        
        <horizontal >
            <text textSize="24" layout_weight="1">功能说明：</text>
            
            {/* <text textColor="black" textSize="18sp" layout_weight="1">评论内容：（一行一条）</text>
            <button id="save" text="保存" w="auto" style="Widget.AppCompat.Button.Borderless.Colored"/> */}
        </horizontal>
        <text>切换到抖音商家的列表页，第一步，采集商家抖音号。</text>
        
        <horizontal >
            <text id="text_run_count">运行数量</text>
            <input id="input_run_count" text="300" hint="请输入运行数量" w="*" layout_gravity="right|top" gravity="right"/>
        </horizontal>
        <horizontal >  
            <button id="btn_ok" text="开始" w="auto" ></button>    
            <button id="btn_tongbu" text="出采集结果" w="auto" ></button>
            <button id="btn_copy" text="复制" w="auto" ></button>
            
        </horizontal>
        <text id="text_guanzhu">采集抖音号结果区：</text>
        <input id="content" h="*" gravity="top" />
        
        
        
    </vertical>
);

// let runCount = 300;
// let guanzhu = 70;
// let dianzan = 70;
// let shoucang = 70;
var storage = storages.create("douyin");
let runCount = storage.get('runCount')||300;
// let guanzhu = storage.get('guanzhu')||70;
// let dianzan = storage.get('dianzan')||70;
// let shoucang = storage.get('shoucang')||70;
// let pinglun = storage.get('pinglun')||70;

ui.input_run_count.setText(runCount+"");
// ui.seekbar_guanzhu.setProgress(parseInt(guanzhu));
// ui.text_guanzhu.setText('关注概率：'+guanzhu+'%');
// ui.seekbar_dianzan.setProgress(parseInt(dianzan));
// ui.text_dianzan.setText('点赞概率：'+dianzan+'%');
// ui.seekbar_shoucang.setProgress(parseInt(shoucang));
// ui.text_shoucang.setText('收藏概率：'+shoucang+'%');
// ui.seekbar_pinglun.setProgress(parseInt(pinglun));
// ui.text_pinglun.setText('评论概率：'+pinglun+'%');
// ui.seekbar_guanzhu.setOnSeekBarChangeListener(new android.widget.SeekBar.OnSeekBarChangeListener({
//     onProgressChanged: function(seekBar, progress, fromUser) {
//         ui.text_guanzhu.setText('关注概率：'+progress+'%')
//     }
// }));
// ui.seekbar_dianzan.setOnSeekBarChangeListener(new android.widget.SeekBar.OnSeekBarChangeListener({
//     onProgressChanged: function(seekBar, progress, fromUser) {
//         ui.text_dianzan.setText('点赞概率：'+progress+'%')
//     }
// }));
// ui.seekbar_shoucang.setOnSeekBarChangeListener(new android.widget.SeekBar.OnSeekBarChangeListener({
//     onProgressChanged: function(seekBar, progress, fromUser) {
//         ui.text_shoucang.setText('收藏概率：'+progress+'%')
//     }
// }));
// ui.seekbar_pinglun.setOnSeekBarChangeListener(new android.widget.SeekBar.OnSeekBarChangeListener({
//     onProgressChanged: function(seekBar, progress, fromUser) {
//         ui.text_pinglun.setText('评论概率：'+progress+'%')
//     }
// }));

ui.btn_ok.click( ()=>  {
	// toast('asdfas')
	// showBLayout.showBLayout()
    // let runCount = ui.input_run_count.getText();
    // console.log("获取到的运行数量为: " + runCount);

    storage.put("runCount", ui.input_run_count.getText()+"");
    // storage.put("guanzhu", ui.seekbar_guanzhu.getProgress()+"");
    // storage.put("dianzan", ui.seekbar_dianzan.getProgress()+"");
    // storage.put("shoucang", ui.seekbar_shoucang.getProgress()+"");
    // storage.put("pinglun", ui.seekbar_pinglun.getProgress()+"");
    // console.log('xxx',storage.get("runCount"));
    // engines.execScriptFile("./douyin.js");
    const common = require('./common.js'); 
    common.openStarBtn("./douyinShop1Do.js");
    app.launchApp("抖音");

})

ui.btn_tongbu.click( ()=>  {
    let douyinNo = formartDouyinNo(storage.get('douyinNo'))
    ui.content.setText(douyinNo);
    storage.put('douyinNo',douyinNo);
})

ui.btn_copy.click( ()=>  {
    setClip(ui.content.getText());
    toastLog('已复制 ')
    // ui.content.setText(storage.get('douyinNo'));
})

function formartDouyinNo(str){
    // 原始字符串
    // var str = "aa,bb,cc,cc";
    str = str + ''
    str = str.replace('undefined','')
    str = str.replace(',,',',')

    // 将字符串拆分成数组
    var arr = str.split(",");
    // 使用 Set 去重
    var uniqueArr = Array.from(new Set(arr));
    // 将去重后的数组重新组合成字符串
    var uniqueStr = uniqueArr.join(",");
    
    return uniqueStr
}
